package 双向无头链表;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: MENG
 * Date: 2022-07-09
 * Time: 20:30
 */
public class Test {
    public static void main(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<Integer>();
        arrayList.add(1);
        arrayList.add(2);
        arrayList.add(3);
//        LinkedList<Number> list = new LinkedList<Number>(arrayList);
        LinkedList<Integer> list = new LinkedList<Integer>(arrayList);
        for (Integer x:list) {
            System.out.println(x+" ");

        }
        System.out.println("================");
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i)+" ");
        }
        System.out.println("================");

        ListIterator it = list.listIterator();
        while(it.hasNext()){
            System.out.println(it.next()+" ");
        }
        System.out.println("=======ListIterator=========");

        //倒叙打印
        ListIterator it2 = list.listIterator(list.size());
        while(it2.hasPrevious()){
            System.out.println(it2.previous()+" ");

        }
        System.out.println("=======ListIterator.hasPrevious=========");


        System.out.println(list.size());
        list.add(0,0);
        System.out.println(list);
        List<Integer> split = list.subList(0,2);
        System.out.println(split);
        list.clear();
        System.out.println(list);



    }
    public static void main1(String[] args) {
        MyLinkedList myLinkedList = new MyLinkedList();
        myLinkedList.addFirst(10);
        myLinkedList.addFirst(12);
        myLinkedList.addFirst(12);

        myLinkedList.addLast(170);
        myLinkedList.addLast(180);

        myLinkedList.display();
        System.out.println(myLinkedList.contains(190));

        //找到下标为1的数据，并从这开始打印
        MyLinkedList.ListNode ret = myLinkedList.findIndex(1);
        myLinkedList.display(ret);
        myLinkedList.remove(180);
        myLinkedList.display();
        myLinkedList.removeAllKey(12);
        myLinkedList.display();
        System.out.println("===============");
        myLinkedList.clear();
        myLinkedList.display();





    }
}
